﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luna;

namespace TextDataExtractor.DEML {
	public class NewObjectAction : AbstractAction {

		public override void execute(ExecutionContext context) {
			string clazz = getArgument("class");
			string varname = getArgument("name");

			if (string.IsNullOrWhiteSpace(clazz))
				throw new ApplicationException("Missing class name in new operation");
			if (string.IsNullOrWhiteSpace(varname))
				throw new ApplicationException("Missing variable name in new operation");

			IList<IDataStorage> clazzStorage = context.getClassStorage(clazz);

			if (!varname.StartsWith("$"))
				varname = "$" + varname;

			DataBag var;
			clazzStorage.Add(var = new DataBag() { Name = varname });
			
			context.setVariable(varname, var);
		}
	}
}
